package com.yaoxiaowen.project2.test.recycler_view;


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yaoxiaowen.project2.R;
import com.yaoxiaowen.project2.util.log.debug.LogInterface;
import com.yaoxiaowen.project2.util.log.debug.LogTool;
import com.yaoxiaowen.project2.util.log.debug.ShowInterface;

import java.util.ArrayList;
import java.util.List;

/**
 * YaoWen(43194) create at tongcheng work pc,
 * time:  2016/12/30 14:37  qq:2669932513
 */
public class RecyclerAdapter extends RecyclerView.Adapter<ViewHolder>{
    private List<String> mDatas = new ArrayList<>();
    private Context mContext;

    public static final String TAG = "RecyclerAdapter";
    private static final LogInterface mLog = LogTool.getLogType();
    private static final boolean DEBUG = true;
    private static final boolean IS_SHOW = true;
    private static ShowInterface mShow;

    public RecyclerAdapter(Context mContext) {
        this.mContext = mContext;
        mShow = LogTool.getShowType(mContext);
    }

    public void resetData(List<String> datas){
        mDatas = datas;
        notifyDataSetChanged();
    }

    private int createCount = 0;
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mLog.i(DEBUG, TAG, "onCreateViewHolder() = " + (createCount++));
        View item = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_test_recycler_view, parent, false);
        return new ViewHolder(item);
    }

    private int bindCount = 0;
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        mLog.i(DEBUG, TAG, "onBindViewHolder() --->>>> " + (bindCount++));
        String content = mDatas.get(position);
        holder.textView.setText(content);
    }

    private  int itemCount = 0;
    @Override
    public int getItemCount() {
        mLog.i(DEBUG, TAG, "getItemCount() ====== " + (itemCount++) + "\t mDatas.size = " + mDatas.size());
        return mDatas.size();
    }
}
